﻿using Microsoft.AspNetCore.Mvc;
using ST.Buz.Base.ViewModel;
using ST.Common.Util.Model;
using ST.Common.Util.Mvc;
using System.Collections.Generic;

namespace ST.Buz.Web.Components
{
	public class MainMenuViewComponent : BaseViewComponent
	{
		//public async Task<IViewComponentResult> InvokeAsync()
		//{
		//	return View();
		//}

		public override IViewComponentResult Invoke()
		{
			try
			{
				UserSession sessionCurrent = GetSessionFromRequest();
				//todo:根据用户权限过滤
				//if (sessionCurrent.Roles.Contains(",admin,"))//admin
				//{
				List<VM_Sys_Module> modulesAll = LoadModulesAll();
				return View(modulesAll);
				//}
				//else
				//{
				//	List<VM_Sys_Module> modulesRole = LoadModulesByRole();
				//	return View(modulesRole);
				//}
			}
			catch (AuthException ex)
			{
				throw ex;
			}
		}

		private List<VM_Sys_Module> LoadModulesAll()
		{
			List<VM_Sys_Module> modules = new List<VM_Sys_Module>();
			modules.Add(new VM_Sys_Module()
			{
				Name = "首页",
				Icon = "fa fa-laptop",
				Code = "/",
				Services = new List<VM_Sys_ModuleService>()
				{
					new VM_Sys_ModuleService(){
						Name="起始页",
						Icon="fa fa-dashboard",
						Code="/index",
						Url="/"
					},
					new VM_Sys_ModuleService(){
						Name="个人中心",
						Icon="ion ion-my",
						Code="/my",
						Url="/my"
					}
				}
			});
			modules.Add(new VM_Sys_Module()
			{
				Name = "会员管理",
				Icon = "ion ion-user",
				Code = "/mall/member",
				Services = new List<VM_Sys_ModuleService>()
				{
					new VM_Sys_ModuleService(){
						Name="会员列表",
						Icon="ion ion-user",
						Code="/mall/member/list",
						Url="/mall/member/list"
					},new VM_Sys_ModuleService(){
						Name="直推图",
						Icon="ion ion-tree",
						Code="/mall/member/pmap",
						Url="/mall/member/pmap"
					}
					//,new VM_Sys_ModuleService(){
					//	Name="接点图",
					//	Icon="fa fa-sitemap",
					//	Code="/mall/member/pmap",
					//	Url="/mall/member/pmap"
					//}
				}
			});
			modules.Add(new VM_Sys_Module()
			{
				Name = "商品管理",
				Icon = "fa fa-book",
				Code = "/mall/product",
				Services = new List<VM_Sys_ModuleService>()
				{
					new VM_Sys_ModuleService(){
						Name="商品列表",
						Icon="fa fa-book",
						Code="/mall/product/list",
						Url="/mall/product/list"
					}
					,new VM_Sys_ModuleService(){
						Name="商品类别",
						Icon="ion ion-tree",
						Code="/mall/productcategory/list",
						Url="/mall/productcategory/list"
					}
				}
			});
			modules.Add(new VM_Sys_Module()
			{
				Name = "订单管理",
				Icon = "fa fa-shopping-cart",
				Code = "/mall/order",
				Services = new List<VM_Sys_ModuleService>()
				{
					new VM_Sys_ModuleService(){
						Name="订单列表",
						Icon="fa fa-shopping-cart",
						Code="/mall/order/list",
						Url="/mall/order/list"
					}
					//,new VM_Sys_ModuleService(){
					//	Name="商品类别",
					//	Icon="ion ion-tree",
					//	Code="/mall/productcat/list",
					//	Url="/mall/productcat/list"
					//}
				}
			});
			modules.Add(new VM_Sys_Module()
			{
				Name = "文章管理",
				Icon = "fa fa-book",
				Code = "/cms/article",
				Services = new List<VM_Sys_ModuleService>()
				{
					new VM_Sys_ModuleService(){
						Name="文章列表",
						Icon="fa fa-file-text",
						Code="/cms/article/list",
						Url="/cms/article/list"
					}
				}
			});
			modules.Add(new VM_Sys_Module()
			{
				Name = "广告管理",
				Icon = "fa fa-book",
				Code = "/mall/ad",
				Services = new List<VM_Sys_ModuleService>()
				{
					new VM_Sys_ModuleService(){
						Name="广告列表",
						Icon="fa fa-file-text",
						Code="/mall/ad/list",
						Url="/mall/ad/list"
					}
				}
			});
			modules.Add(new VM_Sys_Module()
			{
				Name = "财务管理",
				Icon = "ion ion-caiwu",
				Code = "/mall/finance",
				Services = new List<VM_Sys_ModuleService>()
				{
					//new VM_Sys_ModuleService(){
					//	Name="奖金统计",
					//	Icon="ion ion-money",
					//	Code="/mall/memberaccount/list",
					//	Url="/mall/memberaccount/list"
					//},
					new VM_Sys_ModuleService(){
						Name="奖金明细",
						Icon="ion ion-liushui",
						Code="/mall/memberbonus/list",
						Url="/mall/memberbonus/list"
					},
					new VM_Sys_ModuleService(){
						Name="提现管理",
						Icon="ion ion-tixian",
						Code="/mall/membercash/list",
						Url="/mall/membercash/list"
					},
					new VM_Sys_ModuleService(){
						Name="转账管理",
						Icon="ion ion-tixian",
						Code="/mall/membertransfer/list",
						Url="/mall/membertransfer/list"
					}
					//new VM_Sys_ModuleService(){
					//	Name="财务统计",
					//	Icon="ion ion-chart-bar",
					//	Code="/mall/finance/stat",
					//	Url="/mall/finance/stat"
					//}
				}
			});
			modules.Add(new VM_Sys_Module()
			{
				Name = "系统管理",
				Icon = "fa fa-cog",
				Code = "/sys",
				Services = new List<VM_Sys_ModuleService>()
				{
					//new VM_Sys_ModuleService(){
					//	Name="日志列表",
					//	Icon="ion ion-user",
					//	Code="/sys/log",
					//	Url="/sys/log/list"
					//},
					new VM_Sys_ModuleService(){
						Name="参数设置",
						Icon="fa fa-cog",
						Code="/sys/config",
						Url="/sys/config"
					}
					//,new VM_Sys_ModuleService(){
					//	Name="会员留言",
					//	Icon="fa fa-comments",
					//	Code="/mall/msg/list",
					//	Url="/mall/msg/list"
					//}
				}
			});
			return modules;
		}

		private List<VM_Sys_Module> LoadModulesByRole()
		{
			List<VM_Sys_Module> modules = LoadModulesAll();
			//todo:只显示当前角色的模块
			return modules;
		}
	}
}
